package cc.rengu.igas.channel.ncqs.core.realize.impl;

import cc.rengu.igas.channel.ncqs.core.realize.NcqsSeqNoService;
import cc.rengu.oltp.service.common.dao.SequenceMapper;
import cc.rengu.oltp.service.common.dao.impl.SequenceMapperImpl;
import cc.rengu.utility.base.TimeUtil;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;

/**
 * 银联无卡快捷支付流水号 on 2019/10/18.
 */
public class NcqsSeqNoServiceImpl implements NcqsSeqNoService {

    @Override
    public String genNcqsSeqNo() throws Exception {
        RgLogger rglog = RgLog.getLogger(this.getClass().getName());
        /**
         * 流水号生成规则 16 位交易流水号组成
         * 规则为：“ 10 位日期” +“ 6 位序列号”
         */
        /*获取从缓存流水号控制位*/
        SequenceMapper sequenceMapper = new SequenceMapperImpl();
        String transSeqNo = sequenceMapper.getNextTransSequenceNo(6);
        if (null == transSeqNo) {
            rglog.error("生成交易流水序列号失败!");
            return null;
        }

        String dateTime = TimeUtil.getDateTime("MMddHHmmss");
        return dateTime + transSeqNo;
    }

}
